//Project: Tenpenny Stories version 0.2 beta
//Coding by: Joshua Black aka JABHackSoul
//Questions email to jabhacksoul@yahoo.com
//Audio Splicing: Vincent Black aka ToonSkull/Evol Child 
//Additional Voices: Vincent Black and Brian Black aka Our Dad as Pendelbury
//Scripting Assistance: ZAZ & ceedj on GTAforums.com

//This script was produced for educational purposes.
//IF you redistribute DON'T REMOVE these comments they help others learn.
//You can add as much as you like but comment on the changes and improvements you made.
// Don't remove old buggy code just comment it out and explain why it was removed.
DEFINE MISSIONS 1              // Total Missions Available
DEFINE MISSION 0 AT @MISSN_02

DEFINE EXTERNAL_SCRIPTS 0 

DEFINE UNKNOWN_EMPTY_SEGMENT 0

DEFINE UNKNOWN_THREADS_MEMORY 500

{$VERSION 3.1.0027}
var
 $PLAYER_CHAR: Player
end // var 
//Main thread starts here
03A4: name_thread 'MAIN' 
//Set the screen BLACK immediately
016A: fade 0 time 0           
01F0: set_max_wanted_level_to 6 
0111: toggle_wasted_busted_check 0 
00C0: set_current_time_hours_to 8 minutes_to 0 
//Loads Tenpenny as #SPECIAL01 or 290
023C: load_special_actor 'TENPEN' as 1 
//Create Player at Station
04E4: unknown_refresh_game_renderer_at 1541 -1675.4 
Camera.SetAtPos(1541.156, -1675.352, 13.55)
$PLAYER_CHAR = Player.Create(#NULL, 1541.156, -1675.352, 13.552)
Player.SetClothes($PLAYER_CHAR, "VEST", "VEST", Torso)
Player.SetClothes($PLAYER_CHAR, "JEANSDENIM", "JEANS", Legs)
Player.SetClothes($PLAYER_CHAR, "SNEAKERBINCBLK", "SNEAKER", Shoes)
Player.SetClothes($PLAYER_CHAR, "PLAYER_FACE", "HEAD", Head)  
Player.Build($PLAYER_CHAR)
//Changes the player to ped model 290 Tenpenny
09C7: change_player $PLAYER_CHAR model_to 290 
01F5: $PLAYER_ACTOR = create_player_actor $PLAYER_CHAR 
07AF: $PLAYER_GROUP = player $PLAYER_CHAR group 
Model.Load(#COPBIKE)
Model.Load(#COPCARLA)
Model.Load(#DESERT_EAGLE)
Model.Load(#COLT45)
038B: load_requested_models 

:MAIN_110
if or
not Model.Available(#COPBIKE)
not Model.Available(#COPCARLA)
not Model.Available(#DESERT_EAGLE)
not Model.Available(#COLT45)
else_jump @MAIN_120 
wait 0 
jump @MAIN_110 
:MAIN_120
0674: set_car_model #COPCARLA numberplate "_CRASH_"
$My_Car = Car.Create(#COPCARLA,  1535.743, -1678.094, 13.09914)
$My_Bike = Car.Create(#COPBIKE, 1535.743, -1665.094, 13.09914)
Car.SetImmunities($My_Car, 0, 1, 0, 0, 0) 
Car.Angle($My_Car) = 0                       //Headed North
Car.DoorStatus($My_Car, 0)                   //No locked doors
053F: set_car $My_Car tires_vulnerability 0  //No popped tries


01B6: set_weather 1 
0001: wait 0 ms 
01B4: toggle_player $PLAYER_CHAR can_move false //We shut down control for the cameras to work 
04BB: select_interior 0 
0629: change_integer_stat 181 to 4 
016C: restart_if_wasted_at 2027.77 -1420.52 15.99 angle 137.0 town_number 0 
016D: restart_if_busted_at 1550.68 -1675.49 14.51 angle 90.0 town_number 0 
// Note: your missions have to use the variable defined here
0180: set_on_mission_flag_to $ONMISSION  
0004: $DEFAULT_WAIT_TIME = 250
03E6: remove_text_box 
$MISSION_1 = 2
// START GAME
$ONMISSION = 0 
01B4: toggle_player $PLAYER_CHAR can_move true               
fade 1 1000 
:MAIN_LOOP
0001: wait $DEFAULT_WAIT_TIME ms
00BF: $TIME_HOURS = current_time_hours, $TIME_MINS = current_time_minutes
// Simple way to start a mission test.
// Just press the Y key.  But you should drive a car to the airport of course.
if and
$ONMISSION == 0
00E1:   player 0 pressed_key 11
jf @MAIN_LOOP
start_mission 0 
0002: jump @MAIN_LOOP 

//--------------------------Catch Carl----------------------

:MISSN_02
thread 'MISSN_02' 
054C: use_GXT_table 'JABM02' 

gosub @MISSN_02_010

00D6: if
0112:   wasted_or_busted
004D: jump_if_false @MISSN_02_900

0050: gosub @MISSN_02_800

jump @MISSN_02_900

:MISSN_02_010 
$ONMISSION = 1
100@ = 0 
//Load Models 
023C: load_special_actor 'PULASKI' as 2 
023C: load_special_actor 'HERN' as 3
Model.Load(#TAXI)
Model.Load(#COPCARLA)
Model.Load(#HMYRI)
Model.Load(#DESERT_EAGLE)
Model.Load(#COLT45)
038B: load_requested_models 
//Check for Models Loading
:MISSN_02_110
if or
823D:   not special_actor 2 loaded 
823D:   not special_actor 3 loaded 
not Model.Available(#TAXI)
not Model.Available(#COPCARLA)
not Model.Available(#DESERT_EAGLE)
not Model.Available(#COLT45)
not Model.Available(#HMYRI)
else_jump @MISSN_02_120
wait 0
jump @MISSN_02_110 

//Setup Bikes Cars and Peds
:MISSN_02_120
0110: clear_player $PLAYER_CHAR wanted_level 
18@ = Actor.Create(8, #SPECIAL02, 1737.5, -2242.0, -2.6953)
Actor.Health(18@) = 1500
Actor.Angle(18@) = 130.0
039E: set_actor 18@ locked 1 while_in_car 
0526: set_actor 18@ stay_in_car 1 
//Define and place Hernandez 8 is GROVE
17@ = Actor.Create(8, #SPECIAL03, 1737.5, -2244.0, -2.6868)
Actor.Health(17@) = 1500
Actor.Angle(17@) = 45.0 
039E: set_actor 17@ locked 1 while_in_car 
0526: set_actor 17@ stay_in_car 1
0746: set_acquaintance 0 of_actors_pedtype 8 to_actors_pedtype 24 // see ped.dat 
0746: set_acquaintance 0 of_actors_pedtype 24 to_actors_pedtype 8 // see ped.dat 
01B2: give_actor $PLAYER_ACTOR weapon 24 ammo 170
01B2: give_actor 18@ weapon 22 ammo 170
01B2: give_actor 17@ weapon 22 ammo 170

14@ = Car.Create(#TAXI, 1799.6714, -2271.1714, 7.0299)
Car.SetImmunities(14@, 0, 0, 0, 0, 0)
Car.Angle(14@) = 0.0
Car.Health(14@) = 1500
0129: 15@ = create_actor_pedtype 4 model #HMYRI in_car 14@ driverseat 
05D1: AS_actor 15@ drive_car 14@ to 1690.1462 -2256.9854 -3.2283 speed 20.0 0 model #NULL 1
16@ = Actor.Create(4, #NULL, 1643.0645, -2239.4258, -2.7024)
Actor.Health(16@) = 100
Actor.Angle(16@) = 185.0
01F7: set_player $PLAYER_CHAR ignored_by_cops 1
0@ = Actor.Car($PLAYER_ACTOR)
Player.CanMove($PLAYER_CHAR) = False
03E5: show_text_box 'CCJ01' 
$7613 = 0
99@ = 1

//Start Mission Play
:MISSN_02_150
068B: set_car 0@ all_disembark 
05CA: AS_actor $PLAYER_ACTOR enter_car 0@ passenger_seat 0 -1 ms
05CA: AS_actor 17@ enter_car 0@ passenger_seat 2 -1 ms
wait 1500
05CB: AS_actor 18@ enter_car 0@ as_driver -1 ms
:MISSN_02_160
wait 0
if and
Actor.DrivingPoliceVehicle($PLAYER_ACTOR)
Actor.DrivingPoliceVehicle(18@)
jf @MISSN_02_160

Actor.DestroyInstantly(18@)
01C8: 18@ = create_actor_pedtype 8 model #SPECIAL01 in_car 0@ passenger_seat 0 
039E: set_actor 18@ locked 1 while_in_car 
0526: set_actor 18@ stay_in_car 1 
072A: put_actor $PLAYER_ACTOR into_car 0@ driverseat 
0430: put_actor 18@ into_car 0@ passenger_seat 0 
09C7: change_player $PLAYER_CHAR model_to 291 
Player.CanMove($PLAYER_CHAR) = True 

//Mission Loop
:MISSN_02_190
 
if or
Car.Wrecked(14@)
Car.Wrecked(0@)
then
gosub @MISSN_02_600
return
end

//This part checks distance between you and CJ
Actor.StorePos($PLAYER_ACTOR, 57@, 58@, 59@)
Actor.StorePos(16@, 60@, 61@, 62@)
050A: 72@ = distance_between_XYZ 57@ 58@ 59@ and_XYZ 60@ 61@ 62@ 
//I zero the meter at 60m anything closer and CJ becomes aware.
000F: 72@ -= 60.0 
if and
72@ < 0.0 
32@ >= 50   //32@ is a timer every 1/20th of a second 
then
32@ = 0 
$7613 += 1  //we add to the awareness.
end
if and
72@ > 0.0   //If you back off
$7613 > 0
32@ >= 10
then
32@ = 0
$7613 -= 1  //we drop the awareness.
end
if 
72@ < 100.0  
then
    98@ = 0  //Reset the message tag.
end
if and
98@ == 0
72@ > 100.0 
then
    03E5: show_text_box 'CCJ09' //You are falling behind.
    98@ = 1
end
if and
98@ == 1
72@ > 200.0 
then
    03E5: show_text_box 'CCJ10' //Close the gap or you will lose him.
    98@ = 2
end
if  or
    72@ >= 250.0    //Quarter kilometer is too much distance and you lose
    $7613 >= 100
then
    03E5: show_text_box 'CCJ06' //You lost him.
    wait 2000
    gosub @MISSN_02_600  //Bad Guy got away!
    return
end
if and
00E1:   player 0 pressed_key 18   //Hit the siren!  replaced with 0ABD:   vehicle 0@ siren_on
00EE:   actor 15@ 0 near_point 2599.8701 -1731.3571 radius 50.0 50.0 in_car 
then
    03E6: remove_text_box 
    jump @MISSN_02_400
end

if and
99@ == 3
72@ <= 100.0  // Cars are within 100m of each other
00EE:   actor 15@ 0 near_point 2599.8701 -1731.3571 radius 25.0 25.0 in_car  //cab on the bridge
then
    99@ = 0
    if 
    $7613 <= 0
    then
    03E5: show_text_box 'CCJ05' //Hit the siren and pull him over!
    else
    03E5: show_text_box 'CCJ04' //You've been spotted pull him over!
    end 
end
 
wait 0 

if  and
    99@ == 1  
    00EE:   actor 15@ 0 near_point 1690.1462 -2256.9854 radius 5.0 5.0 in_car 
then
    99@ = 2
    03E5: show_text_box 'CCJ02' //Pendelbury's note
    05D1: AS_actor 15@ drive_car 14@ to 1644.0234 -2251.3909 -3.2139 speed 20.0 0 model #NULL 0
    067C: put_camera_on_actor 16@ with_offset 0.0 2.0 1.0 rotation 0.0 0.0 0.0 0.0 2 
    wait 3000
    Camera.Restore_WithJumpCut 
    Camera.SetBehindPlayer       
end
//CJ gets in cab
if 
    00EE:   actor 15@ 0 near_point 1644.0234 -2251.3909 radius 5.0 5.0 in_car 
then    
    if
        not Actor.InCar(16@ 14@)
    then
        05CA: AS_actor 16@ enter_car 14@ passenger_seat 2 -1 ms
        0526: set_actor 16@ stay_in_car 1 
        wait 2000
    else
        05D1: AS_actor 15@ drive_car 14@ to 1582.1906 -2250.7629 -3.2166 speed 20.0 0 model #NULL 0
        0187: 90@ = create_marker_above_actor 16@
        07E0: set_marker 90@ type_to 0
        0165: set_marker 90@ color_to 0 
    end
end
//Follow him - sets up Spook-o-meter
if and
    99@ == 2
    00EE:   actor 15@ 0 near_point 1582.1906 -2250.7629 radius 5.0 5.0 in_car
then
    99@ = 3
    05D1: AS_actor 15@ drive_car 14@ to 1574.6929 -2281.6812 -3.3396 speed 20.0 3 model #NULL 0
    03E5: show_text_box 'CCJ03'
    03C4: set_status_text $7613 type 1 GXT 'CCJ08'       
end
if
    00EE:   actor 15@ 0 near_point 1574.6929 -2281.6812 radius 5.0 5.0 in_car
then
    05D1: AS_actor 15@ drive_car 14@ to  1525.8585 -2284.6538 -3.358   speed 20.0 3 model #NULL 0
end
if
    00EE:   actor 15@ 0 near_point 1525.8585 -2284.6538 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1469.524 -2238.1492 -3.3573   speed 20.0 3 model #NULL 0
end
if
    00EE:   actor 15@ 0 near_point 1469.524 -2238.1492 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1425.4841 -2306.5234 -2.5092  speed 20.0 3 model #NULL 0
end
if
    00EE:   actor 15@ 0 near_point 1425.4841 -2306.5234 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1413.7415 -2436.7915 5.7157   speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1413.7415 -2436.7915 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1359.2112 -2434.5842 8.0555   speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1359.2112 -2434.5842 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1347.7893 -2317.927 13.0194   speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1347.7893 -2317.927 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1358.9454 -2191.8879 13.0331  speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1358.9454 -2191.8879 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1530.0697 -2131.3728 13.8876  speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1530.0697 -2131.3728 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1652.3665 -2051.2178 21.3076  speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1652.3665 -2051.2178 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1612.8522 -1649.199 28.2051   speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1612.8522 -1649.199 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1670.9551 -1557.9021 23.9628  speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1670.9551 -1557.9021 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  1819.3809 -1517.3971 5.3928   speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 1819.3809 -1517.3971 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  2110.5933 -1535.0817 2.0947   speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 2110.5933 -1535.0817 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  2342.1223 -1619.6182 6.1786   speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 2342.1223 -1619.6182 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  2708.0864 -1628.4835 12.9286  speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 2708.0864 -1628.4835 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  2721.2412 -1643.2512 12.6293  speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 2721.2412 -1643.2512 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  2652.9104 -1657.0725 10.3364  speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 2652.9104 -1657.0725 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  2640.5854 -1718.923 10.3577   speed 35.0 3 model #NULL 1
end
if
    00EE:   actor 15@ 0 near_point 2640.5854 -1718.923 radius 5.0 5.0 in_car
then
05D1: AS_actor 15@ drive_car 14@ to  2486.5171 -1730.9998 13.0176  speed 20.0 3 model #NULL 1
end
if 
    00EE:   actor 15@ 0 near_point 2486.5171 -1730.9998 radius 5.0 5.0 in_car 
then
    05D1: AS_actor 15@ drive_car 14@ to 2483.7603 -1675.0305 12.9709 speed 20.0 3 model #NULL 1
end
if 
    00EE:   actor 15@ 0 near_point 2483.7603 -1675.0305 radius 5.0 5.0 in_car 
then
    gosub @MISSN_02_600  //Bad Guy got away!
    return
end

if
Actor.Dead($PLAYER_ACTOR)
jf @MISSN_02_190
return

:MISSN_02_400
016A: fade 0 time 1000 
gosub @MISSN_02_800  //Sucess!
return
 
:MISSN_02_600
0151: remove_status_text $7613
09C7: change_player $PLAYER_CHAR model_to 290 //Change into Tenpenny
034F: destroy_actor_with_fade 17@             //Ghost the help
034F: destroy_actor_with_fade 18@ 

00BA: show_text_styled GXT 'M_FAIL' time 5000 style 1  // ~r~MISSION FAILED!
//$CRASH_MARKER = Marker.CreateIconAndSphere(16, 1728.5, -2251.8508, -3.2548)
$CRASH_MARKER = Marker.CreateIconAndSphere(16, 1694.5817, -2251.8508, -3.2548)

return

:MISSN_02_800
wait 0
if
816B:   not fading 
jf @MISSN_02_800
09C7: change_player $PLAYER_CHAR model_to 290 
034F: destroy_actor_with_fade 17@ 
034F: destroy_actor_with_fade 18@ 

0151: remove_status_text $7613
Car.PutAt(14@,-673.0, 2705.0, 700.0)
Actor.PutAt(15@,-673.0, 2705.0, 700.0)
Actor.PutAt(16@,-673.0, 2705.0, 700.0)
set_weather 14 
054C: use_GXT_table 'INTRO1' 

select_interior 0 
02E4: load_cutscene_data 'PROLOG3' 

:MISSN_02_810
wait 0
if 
06B9:   cutscene_data_loaded 
jf @MISSN_02_810 

Model.Load(#GWFORUM1_LAE)

:MISSN_02_815
wait 0 
if 
   Model.Available(#GWFORUM1_LAE)
jf @MISSN_02_815

0A0B: set_rendering_origin_at_3D_coord 2493.362 -1734.295 12.3828 angle 258.7583 
0395: clear_area 1 at 2482.582 -1729.642 12.3906 radius 500.0 
02E7: start_cutscene 
016A: fade 1 time 1000 

:MISSN_02_820
wait 0
if 
02E9:   cutscene_reached_end 
jf @MISSN_02_820

02EA: end_cutscene 
Model.Destroy(#GWFORUM1_LAE)
03CB: set_rendering_origin_at 1550.68 -1675.49 14.51
Actor.PutAt($PLAYER_ACTOR, 1550.68, -1675.49, 14.51)
016A: fade 1 time 1500 

:MISSN_02_840
wait 0
if
816B:   not fading 
jf @MISSN_02_840

$MISSION_TP += 1
$CRASH_TOTAL_PASSED_MISSIONS += 1 
030C: progress_made += 1 
0394: play_music 1 
Player.ClearWantedLevel($PLAYER_CHAR)
01E3: show_text_1number_styled GXT 'M_PASS' number 2000 time 5000 style 1  // MISSION PASSED!~n~~w~$~1~
Player.Money($PLAYER_CHAR) += 2000
$CRASH_MARKER = Marker.CreateIconAndSphere(16, 1541.156, -1675.352, 13.552)
return 

:MISSN_02_900
$ONMISSION = 0 
01BD: $CURRENT_TIME_IN_MS = current_time_in_ms
0164: disable_marker 90@
Model.Destroy(#TAXI)
Model.Destroy(#HMYRI)
Model.Destroy(#COPCARLA)
Model.Destroy(#DESERT_EAGLE)
Model.Destroy(#COLT45)
mission_cleanup 
end_thread 
